import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    chooseClose: "close",
    PowerOn: false,
    infoCopy: {},
    musicInfo: {
      mini: false,
      float: false,
      shuffle: false,
      repeat: 'no-repeat',
      showLrc: true,
      isAutoplay: false,
      showAplayer: false,
      musicList: [],
      music: {
        title: "网易云音乐",
        artist: "无",
        src:
          "https://bjetxgzv.cdn.bspapp.com/VKCEYUGU-hello-uniapp/2cc220e0-c27a-11ea-9dfb-6da8e309e0d8.mp3",
        pic: "../assets/wangyiyunIcon.png",
        lrc: "",
      },
    },
  },
  mutations: {
    isChange(state, chooseValue) {
      state.chooseClose = chooseValue;
    },
    boFangSing(state, payload) {
      let str = "";
      state.musicInfo.music.title = payload.name;
      state.musicInfo.music.pic = payload.picUrl;
      for (let i = 0; i < payload.artists.length; i++) {
        if (payload.artists[i].name) {
          str += payload.artists[i].name + "/";
        }
      }
      state.musicInfo.music.artist = str.substr(0, str.length - 1);
      state.musicInfo.music.src = payload.src;
      state.musicInfo.music.lrc = payload.lrc;
      let info = {
        title: payload.name,
        artist: str.substr(0, str.length - 1),
        src: payload.src,
        pic: payload.picUrl,
        id: payload.id,
        lrc: payload.lrc,
      };
      if (state.musicInfo.musicList.length == 0) {
        state.musicInfo.musicList.push(info);
        localStorage.setItem("musicInfo", JSON.stringify(info));
        localStorage.setItem(
          "musicList",
          JSON.stringify(state.musicInfo.musicList)
        );
      } else {
        if (
          JSON.stringify(state.musicInfo.musicList).indexOf(
            JSON.stringify(info.id)
          ) == -1
        ) {
          state.musicInfo.musicList.push(info);
          localStorage.setItem("musicInfo", JSON.stringify(info));
          localStorage.setItem(
            "musicList",
            JSON.stringify(state.musicInfo.musicList)
          );
        }
      }
    },
  },
  actions: {
    boFangSing(context, payload) {
      context.commit("boFangSing", payload);
    },
  },
  modules: {},
});
